package com.example.moblie203zlw20216061300604;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.sql.SQLData;

public class MainActivity extends AppCompatActivity {
    SQLData sqlData;
    private TextView tvMainTitle;
    private TextView tvMainConnState;
    private TextView tvMainReadOrWrite;
    private TextView tvMainVersion;
    private TextView tvMainPath;
    private Button btnMainOpenDB;
    private Button btnMainCloseDB;
    private sqlistadpter sqlistadpter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        sqlistadpter=new sqlistadpter();
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tvMainTitle);
        tvMainConnState = (TextView) findViewById(R.id.tvMainConnState);
        tvMainReadOrWrite = (TextView) findViewById(R.id.tvMainReadOrWrite);
        tvMainVersion = (TextView) findViewById(R.id.tvMainVersion);
        tvMainPath = (TextView) findViewById(R.id.tvMainPath);
        btnMainOpenDB = (Button) findViewById(R.id.btnMainOpenDB);
        btnMainCloseDB = (Button) findViewById(R.id.btnMainCloseDB);
    }
    public void button(View view) {
        switch (view.getId()){
            case R.id.btnMainOpenDB:
                sqlistadpter.onpe(MainActivity.this);
                if (sqlistadpter.open()){
                    tvMainConnState.setText("数据库已经打开");
                    tvMainPath.setText("数据库路径:"+sqlistadpter.path());
                    tvMainReadOrWrite.setText("数据库"+(sqlistadpter.isread()?"只读":"可写"));
                    tvMainVersion.setText("数据库版本号:"+sqlistadpter.getversion());
                }
                break;
            case R.id.btnMainCloseDB:
                sqlistadpter.off(MainActivity.this);
                tvMainConnState.setText("数据库已关闭");
                tvMainPath.setText("数据库已关闭");
                tvMainReadOrWrite.setText("数据库已关闭");
                tvMainVersion.setText("数据库已关闭");
                break;
        }
    }
}